{include file="public/header" /}



<div class="page">

    <form id="answer_form" method="post" name="articleClassForm">
        <table class="ds-default-table">
            <tbody>
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation" for="ac_name">内容:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <input type="text" name="content" id="content" class="txt"><input class="btn btn-small" id="add" type="button" value="{$Think.lang.ds_add}"/>
                    <input type="hidden" value="{$answerid}" name="id" id="answerid" class="txt">
                </td>
            </tr>
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation" for="ac_name">处理方法:</label>
                </td>
            </tr>
            {notempty name="method_list"}
            {foreach $method_list as $key => $val}
            <tr class="noborder delete_{$val->id}">
                <td class="vatop rowform">
                    {$val->content} <button type="button" class="btn btn-danger btn-small delete" onclick="deleteMethod($(this))" data-content="{$val->content}" data-id="{$val->id}">删除</button>
                </td>
            </tr>
            {/foreach}
            {/notempty}
            </tbody>
            <tfoot>
            <tr class="tfoot">
                <td colspan="15" >

                </td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>
<script type="text/javascript" src="{$Think.ADMIN_SITE_ROOT}/js/jquery.edit.js" charset="utf-8"></script>
<script type="text/javascript">
    function deleteMethod(that) {
        var content = that.attr('data-content');
        var answer_id = $('#answerid').val();
        var method_id = that.attr('data-id');
        layer.confirm('确定要解除"'+that.attr('data-content')+'"处理办法吗', {
            btn: ['确定', '取消'],
            title: false,
        }, function () {

            console.log(method_id);
            $.get('deleteMethod?answer_id='+answer_id+'&method_id='+method_id, function (res) {
                res = JSON.parse( res );
                layer.msg(res.message);
                if (res.code == 10000) {
                    $('.delete_'+method_id).remove();
                }
            }, 'json')
        })
    }
    $('#add').click(function () {
        var id = $('#answerid').val();
        var content = $('#content').val();
        if (!content) {
            layer.msg('内容不能为空');
            return false;
        }
        $.post('addMethod?id='+id, {
            content: content
        }, function (res) {
            res = JSON.parse( res );
            layer.msg(res.message);
            if (res.code == 10000) {
                var html = '<tr class="noborder delete_'+res.id+'">\n' +
                    '                <td class="vatop rowform">\n' +
                    '                    '+content+' <button type="button" class="btn btn-danger btn-small" onclick="deleteMethod($(this))" data-content="'+content+'" data-id="'+res.id+'">删除</button>\n' +
                    '                </td>\n' +
                    '            </tr>';
                $('tbody').append(html)
            }
            $('#content').val('');
        })
    })



    $('.delete').click(function () {
        deleteMethod($(this))

    })

</script>
